package com.xy.learn.springlearn.config;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Service;

@Service
@Aspect
public class AopConfig {

    @Before("execution(* com.xy.learn.springlearn.service.ElectricService.charge(..))")
    public void beforeExecute(JoinPoint joinPoint) throws Throwable {
        System.out.println("before... 等待两秒");
        Thread.sleep(2000);
    }

    @Around("execution(* com.xy.learn.springlearn.service.ElectricService.pay(..))")
    public void recordPayPerformance(ProceedingJoinPoint joinPoint) throws Throwable {
        long start = System.currentTimeMillis();
        joinPoint.proceed();
        long end = System.currentTimeMillis() - start;
        System.out.println("耗时:" + (end - start));
    }
}
